(function($, undefined){
    window.initReportButtons = function(gridId, exportUrl, filterSelectors){
        if (gridId.length > 0) {
            var inputSelector = '#' + gridId + ' .filters input, ' + '#' + gridId
                + ' .filters select';

            if (filterSelectors.length > 0) {
                for (var selector in filterSelectors) {
                    inputSelector += ', ' + filterSelectors[selector];
                }
            }

            var data;

            $('#reset-filters').on('click', function() {
                $(inputSelector).each( function(i, o) {
                    $(o).val('');
                });

                data = $.param($(inputSelector));

                $('#' + gridId).yiiGridView('update', {data: data});
                return false;
            });

            $('#generate-report').on('click', function(e) {
                e.preventDefault();

                exportUrl += '?' + $.param($(inputSelector)) + '&ajax=' + gridId + '&generateReport=1';

                window.location.href = exportUrl;
            });
        }
    }
})(jQuery);
